public class Demo1 {
    public static void main(String[] args) {
        System.out.println("主线程开始执行");
        
        // 通过创建Thread的子类方式来创建线程
        Thread thread = new MyThread();
        // 调用start方法启动线程
        thread.start();
        while(true){
            System.out.println("hello main");
            try {
                
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
//具名类 有具体ThreadMy
// 创建Thread的子类
class MyThread extends Thread {
    @Override
    public void run() {
        // 线程内部打印hello thread
        while(true){
          System.out.println("hello thread");  
          try {
            Thread.sleep(1000);
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
        }
    }
}


